﻿@{
    ViewBag.Title = "枚举列表";
    Layout = "~/Views/Shared/_LayoutList.cshtml";

    var grid = Html.DWZGridFor<EnumType>()
        .ID("grdList")
        .Action(@Url.Action("EnumInfoList"))
        .Width("mainWidth")
        .ExtParam(new { ParentId = "$('#ParentId').val()" })
    .Columns(col =>
    {
        col.Bind(e => e.Id).IsKey();
        col.Bind(e => e.TypeCode).Width(120).AsQuery().Align(FlexiGridAlign.Left);
        col.Bind(e => e.TypeName).Width(100).AsQuery().Align(FlexiGridAlign.Left);
        col.Bind(e => e.Remark).Width("auto").Align(FlexiGridAlign.Left);
        col.Bind(e => e.SeqNo).Width(40);
        col.Bind(e => e.UpdateUser).Width(60);
        col.Bind(e => e.UpdateDate).Width(70).DateFormat("yyyy-MM-dd");
        col.Bind(e => e.Id, "操作", 120).Sortable(false)
            .Template(Url.EditLink("EditDictInfo", "编辑枚举类型")
            + Url.DeleteLink("DeleteEnumInfo", "${TypeName}"));
    })
    .Buttons(btn =>
    {
        btn.Bind("Add", "新建枚举类型", FlexiGridButtonType.Add).Action(@Url.Action("EditDictInfo")).OnPress("OpenFormDailog");
    });

    var gridItem = Html.DWZGridFor<EnumItem>()
        .ID("grdItemList")
        .Action(@Url.Action("EnumItemList"))
        .Width("mainWidth")
        .ExtParam(new { ParentId = "$('#ParentId').val()" })
        .Columns(col =>
        {
            col.Bind(e => e.Id).IsKey();
            col.Bind(e => e.EnumCode).Width(120).AsQuery().Align(FlexiGridAlign.Left);
            col.Bind(e => e.EnumName).Width(100).AsQuery().Align(FlexiGridAlign.Left);
            col.Bind(e => e.Remark).Width("auto").Align(FlexiGridAlign.Left);
            col.Bind(e => e.SeqNo).Width(40);
            col.Bind(e => e.UpdateUser).Width(60);
            col.Bind(e => e.UpdateDate).Width(70).DateFormat("yyyy-MM-dd");
            col.Bind(e => e.Id, "操作", 220).Sortable(false)
                .Template(Url.EditLink("EditEnumItem", "编辑枚举项")
                + Url.DeleteLink("DeleteEnumItem", "${EnumName}")
                + Url.GridLink("setuser", "查看子枚举", "ViewSubItem('${Id}','${EnumName}')"));
        })
        .Buttons(btn =>
        {
            btn.Bind("Add", "新建枚举项", FlexiGridButtonType.Add).OnPress("AddEnumItem");
        });
}
@Html.Css("tree")
@Html.Js("tree")
<script type="text/javascript">
    var maiheight = document.documentElement.clientHeight;
    var mainWidth = document.documentElement.clientWidth - 3 - 170; // 减去边框和左边的宽度
    var otherpm = 82;
    var gh = maiheight - otherpm;
    $(document).ready(function () {
        // 部门树控件
        $("#Tree").treeview({
            url: '@Url.Action("EnumTree")',
            showcheck: false,
            onnodeclick: TreeNode_Click,
            theme: "bbit-tree-no-lines" //bbit-tree-lines ,bbit-tree-no-lines,bbit-tree-arrows
        }).height(maiheight - 30);
        function TreeNode_Click(data) {
            // 刷新字典项列表
            if (data.value != "") {
                $("#grdItemList").flexOptions({ extParam: [{ name: "typeCode", value: data.value}] }).flexReload();
                $("#divType").hide();
                $("#divItem").show();

            }
            else { // 显示字典类型列表
                $("#divType").show();
                $("#divItem").hide();
            }
            $("#ParentId").val(data.value);
            $("#ListTitle").text(data.text);
        }
    });

    // 添加枚举项
    function AddEnumItem() {
        var url = '@Url.Action("EditEnumItem")?TypeCode=' + $("#ParentId").val();
        OpenModelWindow(url, { width: 470, height: 330, caption: "添加枚举", onclose: refreshGrid });
        return false;
    }

    // 查看子枚举
    function ViewSubItem(Id, name) {
        OpenModelWindow('@Url.Action("ViewSubEnumItem")?parentId=' + Id, { width: 800, height: 530, caption: "子枚举列表（" + name + "）" });
    }

    // 重载刷新列表Grid
    function refreshGrid() {
        // 刷新列表
        showLoadingMsg("操作成功", { left: 300, top: 2 }, true, 3000);
        if ($('#ParentId').val() != "") {
            $("#grdItemList").flexReload();
        }
        else {
            $("#grdList").flexReload();
        }

        // 同步刷新根节点
        $("#Tree").refresh("");
    }
</script>
<div class="MainContainer" style="overflow: hidden;">
    <table width="100%" cellpadding="0" cellspacing="0" class="tree_grid_panel_table">
        <tbody>
            <tr>
                <td style="width: 170px;">
                    <div class="header">
                        <span class="title">枚举树</span></div>
                    <div id="Tree" class="treeview">
                    </div>
                </td>
                <td style="width: 2px;">
                </td>
                <td>
                    <div class="header">
                        <span id="ListTitle" class="title">枚举列表</span></div>
                    <div id="divType">
                        @Html.Raw(grid.ToString())
                    </div>
                    <div id="divItem" style="display: none">
                        @Html.Raw(gridItem.ToString())
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
    @Html.Hidden("ParentId")
</div>
